#ifndef CODE_H
#define CODE_H
#include <assert.h>
#define MIPS32_BITS(value, start, count) (((value) >> (start)) & ((1 << (count)) - 1))
#define MIPS32_SIGN(value, signbit) (-(((value) >> (signbit)) & 1))

#define MIPS32_ENCODE_I_IMM(imm) (MIPS32_BITS((imm), 0, 16) << 0)
#define MIPS32_ENCODE_R_IMM(imm) (MIPS32_BITS((imm), 0, 4) << 6)
#define MIPS32_ENCODE_J_IMM(imm) (MIPS32_BITS((imm), 0, 26) << 0)

#define MIPS32_DECODE_I_IMM(ins) ((MIPS32_BITS((ins), 0, 16) << 0) | (MIPS32_SIGN(ins,15) << 16))
#define MIPS32_DECODE_U_IMM(ins) ((MIPS32_BITS((ins), 0, 16) << 0))
#define MIPS32_DECODE_R_IMM(ins) (MIPS32_BITS((ins), 0, 4) << 6)
#define MIPS32_DECODE_J_IMM(ins) (MIPS32_BITS((ins), 0, 26) << 0)

#define MIPS32_VALID_REG(value) (MIPS32_BITS((value), 0, 5) == (value))

#define MIPS32_VALID_I_IMM(value)                                       \
	(MIPS32_DECODE_I_IMM(MIPS32_ENCODE_I_IMM (value)) == (value))

#define _mips32_emit(p, insn)                   \
	do {                                        \
		*(uint32_t *) (p) = (insn);             \
		(p) += sizeof (uint32_t);               \
	} while (0)


/*
 * The R-type encoding is used for a variety of instructions that operate on
 * registers only, such as most integer instructions, atomic instructions, and
 * some floating point instructions.
 *
 * [31....26] special
 * [25...21] rs
 * [20...16] rt
 * [15...11] rd
 * [10...6]  fmt
 * [5...0]   opcode
 */

#define mips32_r_op(p, opcode, fmt, special, rs, rt, rd)    \
	do {                                                    \
		assert (MIPS32_VALID_REG ((rd)));                   \
		assert (MIPS32_VALID_REG ((rs)));                   \
		assert (MIPS32_VALID_REG ((rt)));                   \
		_mips32_emit ((p), ((opcode) << 0) |                \
                      ((fmt) << 6) |                        \
                      ((rd) << 11) |                        \
                      ((rt) << 16) |                        \
                      ((rs) << 21) |                        \
                      ((special) << 26));                   \
	} while (0)


/*
 * The R4-type encoding is used for a variety of instructions that operate on
 * registers only, such as most integer instructions, atomic instructions, and
 * some R type with imm point instructions.
 *
 * [31....26] special
 * [25...21] rs
 * [20...16] rt
 * [15...11] rd
 * [10...6]  fmt
 * [5...0]   opcode
 */

#define mips32_r4_op(p, opcode, imm,  func, special, rt, rd) \
	do {                                                    \
		assert (MIPS32_VALID_REG ((rd)));                   \
		assert (MIPS32_VALID_REG ((rt)));                   \
		_mips32_emit ((p), ((opcode) << 0) |                \
                      ((imm) << 6) |                        \
                      ((rd) << 11) |                        \
                      ((rt) << 16) |                        \
                      ((func) << 21) |                      \
                      ((special) << 26));                   \
	} while (0)

/*
 * The f-type encoding is used for floating point fused multiply-add instructions.
 *
 * [31....26] special
 * [25...21]  fmt
 * [20...16]  ft
 * [15...11]  fs
 * [10...6]   fd
 * [5...0]   opcode
 */

#define mips32_f_op(p, opcode, fmt, special, fs, ft, fd)    \
	do {                                                    \
		assert (MIPS32_VALID_REG ((fd)));                   \
		assert (MIPS32_VALID_REG ((fs)));                   \
		assert (MIPS32_VALID_REG ((ft)));                   \
		_mips32_emit ((p), ((opcode) << 0) |                \
                      ((fd) << 6) |                         \
                      ((fs) << 11) |                        \
                      ((ft) << 16) |                        \
                      ((fmt) << 21) |                       \
                      ((special) << 26));                   \
	} while (0)


/*
 * The I-type encoding is used for a variety of instructions, such as ADDI,
 * loads, and most integer instructions that operate on immediates.
 *
 * [31...26] opcode
 * [25...21] rs
 * [20...16] rt
 * [16....0] imm[0..16]
 */

#define mips32_i_op(p, opcode, rs, rt, imm)                     \
	do {                                                        \
		assert (MIPS32_VALID_REG ((rs)));                       \
		assert (MIPS32_VALID_REG ((rt)));                       \
        assert(MIPS32_VALID_I_IMM(imm));                        \
		_mips32_emit ((p), ((opcode) << 26) |                   \
                      ((rs) << 21) |                            \
                      ((rt) << 16) |                            \
                      (MIPS32_ENCODE_I_IMM ((int32_t) (imm)))); \
	} while (0)



/*
 * The J-type encoding is used for conditional branches with signed offsets.
 *
 * [31...26] opcode
 * [25....0] imm[26]
 */
#define mips32_j_op(p, opcode, imm)                             \
	do {                                                        \
		_mips32_emit ((p), ((opcode) << 26) |                   \
                      (MIPS32_ENCODE_J_IMM ((int32_t) (imm)))); \
	} while (0)

#define mips32_nop(p)                    mips32_r_op(p,0x00,0x00,0x00,0x00,0x00,0x00)
#define mips32_ssnop(p)                  mips32_r_op(p,0x00,0x01,0x00,0x00,0x00,0x00)
#define mips32_ehb(p)                    mips32_r_op(p,0x00,0x03,0x00,0x00,0x00,0x00)
#define mips32_add(p,rs,rt,rd)           mips32_r_op(p,0x20,0x00,0x00,rs,rt,rd)
#define mips32_addu(p,rs,rt,rd)          mips32_r_op(p,0x21,0x00,0x00,rs,rt,rd)
#define mips32_and(p,rs,rt,rd)           mips32_r_op(p,0x24,0x00,0x00,rs,rt,rd)
#define mips32_break(p)                  mips32_r_op(p,0x0d,0x00,0x00,0x00,0x00,0x00)
#define mips32_cfc1(p,rt,rd)             mips32_r_op(p,0x00,0x00,0x11,0x02,rt,rd)
#define mips32_clz(p,rs,rt,rd)           mips32_r_op(p,0x20,0x00,0x1c,rs,rt,rd)
#define mips32_ctc1(p,rt,rd)             mips32_r_op(p,0x00,0x00,0x11,0x06,rt,rd)
#define mips32_div(p,rs,rt)              mips32_r_op(p,0x1a,0x00,0x00,rs,rt,0x00)
#define mips32_divu(p,rs,rt)             mips32_r_op(p,0x1b,0x00,0x00,rs,rt,0x00)
#define mips32_ext(p,rs,rt,rd)           mips32_r_op(p,0x00,0x00,0x1f,rs,rt,rd)
#define mips32_ins(p,rs,rt,rd)           mips32_r_op(p,0x04,0x00,0x1f,rs,rt,rd)
#define mips32_jr(p,rs)                  mips32_r_op(p,0x08,0x00,0x00,rs,0x00,0x00)
#define mips32_jr_hb(p,rs)               mips32_r_op(p,0x08,0x10,0x00,rs,0x00,0x00)
#define mips32_jalr(p,rs)                mips32_r_op(p,0x09,0x00,0x00,rs,0x00,0x1f)
#define mips32_jalr_r(p,rs,rd)           mips32_r_op(p,0x09,0x00,0x00,rs,0x00,rd)
#define mips32_jalr_hb(p,rs)             mips32_r_op(p,0x09,0x10,0x00,rs,0x00,0x1f)
#define mips32_jalr_r_hb(p,rs,rd)        mips32_r_op(p,0x09,0x10,0x00,rs,0x00,rd)
#define mips32_ldxc1(p,rs,rt)            mips32_r_op(p,0x01,0x00,0x13,rs,rt,0x00)
#define mips32_madd(p,rs,rt)             mips32_r_op(p,0x00,0x00,0x1c,rs,rt,0x00)
#define mips32_maddu(p,rs,rt)            mips32_r_op(p,0x01,0x00,0x1c,rs,rt,0x00)
#define mips32_mfc1(p,rt,rd)             mips32_r_op(p,0x00,0x00,0x11,0x00,rt,rd)
#define mips32_mfhc1(p,rt,rd)            mips32_r_op(p,0x00,0x00,0x11,0x03,rt,rd)
#define mips32_mfhi(p,rd)                mips32_r_op(p,0x10,0x00,0x00,0x00,0x00,rd)
#define mips32_movf(p,rs,rd)             mips32_r_op(p,0x01,0x00,0x00,rs,0x00,rd)
#define mips32_movn(p,rs,rt,rd)          mips32_r_op(p,0x0b,0x00,0x00,rs,rt,rd)
#define mips32_movz(p,rs,rt,rd)          mips32_r_op(p,0x0a,0x00,0x00,rs,rt,rd)
#define mips32_msub(p,rs,rt)             mips32_r_op(p,0x04,0x00,0x1c,rs,rt,0x00)
#define mips32_msubu(p,rs,rt)            mips32_r_op(p,0x05,0x00,0x1c,rs,rt,0x00)
#define mips32_mtc1(p,rt,rd)             mips32_r_op(p,0x00,0x00,0x11,0x04,rt,rd)
#define mips32_mthc1(p,rt,rd)            mips32_r_op(p,0x00,0x00,0x11,0x07,rt,rd)
#define mips32_mtlo(p,rs)                mips32_r_op(p,0x13,0x00,0x00,rs,0x00,0x00)
#define mips32_mul(p,rs,rt,rd)           mips32_r_op(p,0x02,0x00,0x1c,rs,rt,rd)
#define mips32_mult(p,rs,rt)             mips32_r_op(p,0x18,0x00,0x00,rs,rt,0x00)
#define mips32_multu(p,rs,rt)            mips32_r_op(p,0x19,0x00,0x00,rs,rt,0x00)
#define mips32_nor(p,rs,rt,rd)           mips32_r_op(p,0x27,0x00,0x00,rs,rt,rd)
#define mips32_or(p,rs,rt,rd)            mips32_r_op(p,0x25,0x00,0x00,rs,rt,rd)
#define mips32_seb(p,rt,rd)              mips32_r_op(p,0x20,0x10,0x1f,0x00,rt,rd)
#define mips32_seh(p,rt,rd)              mips32_r_op(p,0x20,0x18,0x1f,0x00,rt,rd)
#define mips32_sllv(p,rs,rt,rd)          mips32_r_op(p,0x04,0x00,0x00,rs,rt,rd)
#define mips32_slt(p,rs,rt,rd)           mips32_r_op(p,0x2a,0x00,0x00,rs,rt,rd)
#define mips32_sltu(p,rs,rt,rd)          mips32_r_op(p,0x2b,0x00,0x00,rs,rt,rd)
#define mips32_srav(p,rs,rt,rd)          mips32_r_op(p,0x07,0x00,0x00,rs,rt,rd)
#define mips32_sub(p,rs,rt,rd)           mips32_r_op(p,0x22,0x00,0x00,rs,rt,rd)
#define mips32_subu(p,rs,rt,rd)          mips32_r_op(p,0x23,0x00,0x00,rs,rt,rd)
#define mips32_sync(p)                   mips32_r_op(p,0x0f,0x00,0x00,0x00,0x00,0x00)
#define mips32_syscall(p)                mips32_r_op(p,0x0c,0x00,0x00,0x00,0x00,0x00)
#define mips32_teq(p,rs,rt)              mips32_r_op(p,0x34,0x00,0x00,rs,rt,0x00)
#define mips32_tge(p,rs,rt)              mips32_r_op(p,0x30,0x00,0x00,rs,rt,0x00)
#define mips32_tgeu(p,rs,rt)             mips32_r_op(p,0x31,0x00,0x00,rs,rt,0x00)
#define mips32_tlt(p,rs,rt)              mips32_r_op(p,0x32,0x00,0x00,rs,rt,0x00)
#define mips32_tltu(p,rs,rt)             mips32_r_op(p,0x33,0x00,0x00,rs,rt,0x00)
#define mips32_tne(p,rs,rt)              mips32_r_op(p,0x36,0x00,0x00,rs,rt,0x00)
#define mips32_wsbh(p,rt,rd)             mips32_r_op(p,0x20,0x02,0x1f,0x00,rt,rd)
#define mips32_xor(p,rs,rt,rd)           mips32_r_op(p,0x26,0x00,0x00,rs,rt,rd)
#define mips32_sll(p,rt,rd,imm)          mips32_r4_op(p,0x00,imm,0x00,0x00,rt,rd)
#define mips32_sra(p,rt,rd,imm)          mips32_r4_op(p,0x03,imm,0x00,0x00,rt,rd)
#define mips32_srl(p,rt,rd,imm)          mips32_r4_op(p,0x02,imm,0x00,0x00,rt,rd)
#define mips32_abs_s(p,fs,fd)            mips32_f_op(p,0x05,0x10,0x11,fs,0x00,fd)
#define mips32_abs_d(p,fs,fd)            mips32_f_op(p,0x05,0x11,0x11,fs,0x00,fd)
#define mips32_abs_ps(p,fs,fd)           mips32_f_op(p,0x05,0x16,0x11,fs,0x00,fd)
#define mips32_add_s(p,fs,ft,fd)         mips32_f_op(p,0x00,0x10,0x11,fs,ft,fd)
#define mips32_add_d(p,fs,ft,fd)         mips32_f_op(p,0x00,0x11,0x11,fs,ft,fd)
#define mips32_add_ps(p,fs,ft,fd)        mips32_f_op(p,0x00,0x16,0x11,fs,ft,fd)
#define mips32_alnv_ps(p,fs,ft,fd)       mips32_f_op(p,0x1e,0x00,0x13,fs,ft,fd)
#define mips32_c_f_d(p,fs,ft)            mips32_f_op(p,0x30,0x11,0x11,fs,ft,0x00)
#define mips32_c_f_s(p,fs,ft)            mips32_f_op(p,0x30,0x10,0x11,fs,ft,0x00)
#define mips32_c_f_ps(p,fs,ft)           mips32_f_op(p,0x30,0x16,0x11,fs,ft,0x00)
#define mips32_c_un_d(p,fs,ft)           mips32_f_op(p,0x31,0x11,0x11,fs,ft,0x00)
#define mips32_c_un_s(p,fs,ft)           mips32_f_op(p,0x31,0x10,0x11,fs,ft,0x00)
#define mips32_c_un_ps(p,fs,ft)          mips32_f_op(p,0x31,0x16,0x11,fs,ft,0x00)
#define mips32_c_eq_d(p,fs,ft)           mips32_f_op(p,0x32,0x11,0x11,fs,ft,0x00)
#define mips32_c_eq_s(p,fs,ft)           mips32_f_op(p,0x32,0x10,0x11,fs,ft,0x00)
#define mips32_c_eq_ps(p,fs,ft)          mips32_f_op(p,0x32,0x16,0x11,fs,ft,0x00)
#define mips32_c_ueq_d(p,fs,ft)          mips32_f_op(p,0x33,0x11,0x11,fs,ft,0x00)
#define mips32_c_ueq_s(p,fs,ft)          mips32_f_op(p,0x33,0x10,0x11,fs,ft,0x00)
#define mips32_c_ueq_ps(p,fs,ft)         mips32_f_op(p,0x33,0x16,0x11,fs,ft,0x00)
#define mips32_c_olt_d(p,fs,ft)          mips32_f_op(p,0x34,0x11,0x11,fs,ft,0x00)
#define mips32_c_olt_s(p,fs,ft)          mips32_f_op(p,0x34,0x10,0x11,fs,ft,0x00)
#define mips32_c_olt_ps(p,fs,ft)         mips32_f_op(p,0x34,0x16,0x11,fs,ft,0x00)
#define mips32_c_ole_d(p,fs,ft)          mips32_f_op(p,0x36,0x11,0x11,fs,ft,0x00)
#define mips32_c_ole_s(p,fs,ft)          mips32_f_op(p,0x36,0x10,0x11,fs,ft,0x00)
#define mips32_c_ole_ps(p,fs,ft)         mips32_f_op(p,0x36,0x16,0x11,fs,ft,0x00)
#define mips32_c_ule_d(p,fs,ft)          mips32_f_op(p,0x37,0x11,0x11,fs,ft,0x00)
#define mips32_c_ule_s(p,fs,ft)          mips32_f_op(p,0x37,0x10,0x11,fs,ft,0x00)
#define mips32_c_ule_ps(p,fs,ft)         mips32_f_op(p,0x37,0x16,0x11,fs,ft,0x00)
#define mips32_c_sf_d(p,fs,ft)           mips32_f_op(p,0x38,0x11,0x11,fs,ft,0x00)
#define mips32_c_sf_s(p,fs,ft)           mips32_f_op(p,0x38,0x10,0x11,fs,ft,0x00)
#define mips32_c_sf_ps(p,fs,ft)          mips32_f_op(p,0x38,0x16,0x11,fs,ft,0x00)
#define mips32_c_ngle_d(p,fs,ft)         mips32_f_op(p,0x39,0x11,0x11,fs,ft,0x00)
#define mips32_c_ngle_s(p,fs,ft)         mips32_f_op(p,0x39,0x10,0x11,fs,ft,0x00)
#define mips32_c_ngle_ps(p,fs,ft)        mips32_f_op(p,0x39,0x16,0x11,fs,ft,0x00)
#define mips32_c_seq_d(p,fs,ft)          mips32_f_op(p,0x3a,0x11,0x11,fs,ft,0x00)
#define mips32_c_seq_s(p,fs,ft)          mips32_f_op(p,0x3a,0x10,0x11,fs,ft,0x00)
#define mips32_c_seq_ps(p,fs,ft)         mips32_f_op(p,0x3a,0x16,0x11,fs,ft,0x00)
#define mips32_c_ngl_d(p,fs,ft)          mips32_f_op(p,0x3b,0x11,0x11,fs,ft,0x00)
#define mips32_c_ngl_s(p,fs,ft)          mips32_f_op(p,0x3b,0x10,0x11,fs,ft,0x00)
#define mips32_c_ngl_ps(p,fs,ft)         mips32_f_op(p,0x3b,0x16,0x11,fs,ft,0x00)
#define mips32_c_lt_d(p,fs,ft)           mips32_f_op(p,0x3c,0x11,0x11,fs,ft,0x00)
#define mips32_c_lt_s(p,fs,ft)           mips32_f_op(p,0x3c,0x10,0x11,fs,ft,0x00)
#define mips32_c_lt_ps(p,fs,ft)          mips32_f_op(p,0x3c,0x16,0x11,fs,ft,0x00)
#define mips32_c_nge_d(p,fs,ft)          mips32_f_op(p,0x3d,0x11,0x11,fs,ft,0x00)
#define mips32_c_nge_s(p,fs,ft)          mips32_f_op(p,0x3d,0x10,0x11,fs,ft,0x00)
#define mips32_c_nge_ps(p,fs,ft)         mips32_f_op(p,0x3d,0x16,0x11,fs,ft,0x00)
#define mips32_c_le_d(p,fs,ft)           mips32_f_op(p,0x3e,0x11,0x11,fs,ft,0x00)
#define mips32_c_le_s(p,fs,ft)           mips32_f_op(p,0x3e,0x10,0x11,fs,ft,0x00)
#define mips32_c_le_ps(p,fs,ft)          mips32_f_op(p,0x3e,0x16,0x11,fs,ft,0x00)
#define mips32_c_ngt_d(p,fs,ft)          mips32_f_op(p,0x3f,0x11,0x11,fs,ft,0x00)
#define mips32_c_ngt_s(p,fs,ft)          mips32_f_op(p,0x3f,0x10,0x11,fs,ft,0x00)
#define mips32_c_ngt_ps(p,fs,ft)         mips32_f_op(p,0x3f,0x16,0x11,fs,ft,0x00)
#define mips32_ceil_l_d(p,fs,fd)         mips32_f_op(p,0x0a,0x11,0x11,fs,0x00,fd)
#define mips32_ceil_l_s(p,fs,fd)         mips32_f_op(p,0x0a,0x10,0x11,fs,0x00,fd)
#define mips32_ceil_w_d(p,fs,fd)         mips32_f_op(p,0x0e,0x11,0x11,fs,0x00,fd)
#define mips32_ceil_w_s(p,fs,fd)         mips32_f_op(p,0x0e,0x10,0x11,fs,0x00,fd)
#define mips32_cvt_d_l(p,fs,fd)          mips32_f_op(p,0x21,0x15,0x11,fs,0x00,fd)
#define mips32_cvt_d_s(p,fs,fd)          mips32_f_op(p,0x21,0x10,0x11,fs,0x00,fd)
#define mips32_cvt_d_w(p,fs,fd)          mips32_f_op(p,0x21,0x14,0x11,fs,0x00,fd)
#define mips32_cvt_l_d(p,fs,fd)          mips32_f_op(p,0x25,0x11,0x11,fs,0x00,fd)
#define mips32_cvt_l_s(p,fs,fd)          mips32_f_op(p,0x25,0x10,0x11,fs,0x00,fd)
#define mips32_cvt_s_pl(p,fs,fd)         mips32_f_op(p,0x28,0x16,0x11,fs,0x00,fd)
#define mips32_cvt_s_pu(p,fs,fd)         mips32_f_op(p,0x20,0x16,0x11,fs,0x00,fd)
#define mips32_cvt_w_d(p,fs,fd)          mips32_f_op(p,0x24,0x11,0x11,fs,0x00,fd)
#define mips32_cvt_w_s(p,fs,fd)          mips32_f_op(p,0x24,0x10,0x11,fs,0x00,fd)
#define mips32_cvt_ps_s(p,fs,ft,fd)      mips32_f_op(p,0x26,0x10,0x11,fs,ft,fd)
#define mips32_div_d(p,fs,ft,fd)         mips32_f_op(p,0x03,0x11,0x11,fs,ft,fd)
#define mips32_div_s(p,fs,ft,fd)         mips32_f_op(p,0x03,0x10,0x11,fs,ft,fd)
#define mips32_floor_l_d(p,fs,fd)        mips32_f_op(p,0x0b,0x11,0x11,fs,0x00,fd)
#define mips32_floor_l_s(p,fs,fd)        mips32_f_op(p,0x0b,0x10,0x11,fs,0x00,fd)
#define mips32_floor_w_d(p,fs,fd)        mips32_f_op(p,0x0f,0x11,0x11,fs,0x00,fd)
#define mips32_floor_w_s(p,fs,fd)        mips32_f_op(p,0x0f,0x10,0x11,fs,0x00,fd)
#define mips32_madd_d(p,fs,ft,fd)        mips32_f_op(p,0x21,0x00,0x13,fs,ft,fd)
#define mips32_madd_s(p,fs,ft,fd)        mips32_f_op(p,0x20,0x00,0x13,fs,ft,fd)
#define mips32_madd_ps(p,fs,ft,fd)       mips32_f_op(p,0x26,0x00,0x13,fs,ft,fd)
#define mips32_mov_d(p,fs,fd)            mips32_f_op(p,0x06,0x11,0x11,fs,0x00,fd)
#define mips32_mov_s(p,fs,fd)            mips32_f_op(p,0x06,0x10,0x11,fs,0x00,fd)
#define mips32_mov_ps(p,fs,fd)           mips32_f_op(p,0x06,0x16,0x11,fs,0x00,fd)
#define mips32_movf_d(p,fs,fd)           mips32_f_op(p,0x11,0x11,0x11,fs,0x00,fd)
#define mips32_movf_s(p,fs,fd)           mips32_f_op(p,0x11,0x10,0x11,fs,0x00,fd)
#define mips32_movf_ps(p,fs,fd)          mips32_f_op(p,0x11,0x16,0x11,fs,0x00,fd)
#define mips32_movn_d(p,fs,ft,fd)        mips32_f_op(p,0x13,0x11,0x11,fs,ft,fd)
#define mips32_movn_s(p,fs,ft,fd)        mips32_f_op(p,0x13,0x10,0x11,fs,ft,fd)
#define mips32_movn_ps(p,fs,ft,fd)       mips32_f_op(p,0x13,0x16,0x11,fs,ft,fd)
#define mips32_movz_d(p,fs,ft,fd)        mips32_f_op(p,0x12,0x11,0x11,fs,ft,fd)
#define mips32_movz_s(p,fs,ft,fd)        mips32_f_op(p,0x12,0x10,0x11,fs,ft,fd)
#define mips32_movz_ps(p,fs,ft,fd)       mips32_f_op(p,0x12,0x16,0x11,fs,ft,fd)
#define mips32_msub_d(p,fs,ft,fd)        mips32_f_op(p,0x29,0x00,0x13,fs,ft,fd)
#define mips32_msub_s(p,fs,ft,fd)        mips32_f_op(p,0x28,0x00,0x13,fs,ft,fd)
#define mips32_msub_ps(p,fs,ft,fd)       mips32_f_op(p,0x2e,0x00,0x13,fs,ft,fd)
#define mips32_mul_d(p,fs,ft,fd)         mips32_f_op(p,0x02,0x11,0x11,fs,ft,fd)
#define mips32_mul_s(p,fs,ft,fd)         mips32_f_op(p,0x02,0x10,0x11,fs,ft,fd)
#define mips32_mul_ps(p,fs,ft,fd)        mips32_f_op(p,0x02,0x16,0x11,fs,ft,fd)
#define mips32_round_l_d(p,fs,fd)        mips32_f_op(p,0x08,0x11,0x11,fs,0x00,fd)
#define mips32_round_l_s(p,fs,fd)        mips32_f_op(p,0x08,0x10,0x11,fs,0x00,fd)
#define mips32_round_w_d(p,fs,fd)        mips32_f_op(p,0x0c,0x11,0x11,fs,0x00,fd)
#define mips32_round_w_s(p,fs,fd)        mips32_f_op(p,0x0c,0x10,0x11,fs,0x00,fd)
#define mips32_rsqrt_d(p,fs,fd)          mips32_f_op(p,0x16,0x11,0x11,fs,0x00,fd)
#define mips32_rsqrt_s(p,fs,fd)          mips32_f_op(p,0x16,0x10,0x11,fs,0x00,fd)
#define mips32_sqrt_d(p,fs,fd)           mips32_f_op(p,0x04,0x11,0x11,fs,0x00,fd)
#define mips32_sqrt_s(p,fs,fd)           mips32_f_op(p,0x04,0x10,0x11,fs,0x00,fd)
#define mips32_trunc_l_d(p,fs,fd)        mips32_f_op(p,0x09,0x11,0x11,fs,0x00,fd)
#define mips32_trunc_l_s(p,fs,fd)        mips32_f_op(p,0x09,0x10,0x11,fs,0x00,fd)
#define mips32_trunc_w_d(p,fs,fd)        mips32_f_op(p,0x0d,0x11,0x11,fs,0x00,fd)
#define mips32_trunc_w_s(p,fs,fd)        mips32_f_op(p,0x0d,0x10,0x11,fs,0x00,fd)
#define mips32_pref(p,rt,rs,imm)         mips32_i_op(p,0x33,rs,rt,imm)
#define mips32_b(p,imm)                  mips32_i_op(p,0x04,0x00,0x00,imm)
#define mips32_bal(p,imm)                mips32_i_op(p,0x01,0x00,0x11,imm)
#define mips32_addi(p,rt,rs,imm)         mips32_i_op(p,0x08,rs,rt,imm)
#define mips32_addiu(p,rt,rs,imm)        mips32_i_op(p,0x09,rs,rt,imm)
#define mips32_bc1f(p,imm)               mips32_i_op(p,0x11,0x08,0x00,imm)
#define mips32_bc1fl(p,imm)              mips32_i_op(p,0x11,0x08,0x02,imm)
#define mips32_bc1t(p,imm)               mips32_i_op(p,0x11,0x08,0x01,imm)
#define mips32_bc1tl(p,imm)              mips32_i_op(p,0x11,0x08,0x03,imm)
#define mips32_beq(p,rt,rs,imm)          mips32_i_op(p,0x04,rs,rt,imm)
#define mips32_beql(p,rt,rs,imm)         mips32_i_op(p,0x14,rs,rt,imm)
#define mips32_bgez(p,rs,imm)            mips32_i_op(p,0x01,rs,0x01,imm)
#define mips32_bgezl(p,rs,imm)           mips32_i_op(p,0x01,rs,0x03,imm)
#define mips32_bgezal(p,rs,imm)          mips32_i_op(p,0x01,rs,0x11,imm)
#define mips32_bgezall(p,rs,imm)         mips32_i_op(p,0x01,rs,0x13,imm)
#define mips32_bgtz(p,rs,imm)            mips32_i_op(p,0x07,rs,0x00,imm)
#define mips32_bgtzl(p,rs,imm)           mips32_i_op(p,0x17,rs,0x00,imm)
#define mips32_blez(p,rs,imm)            mips32_i_op(p,0x06,rs,0x00,imm)
#define mips32_blezl(p,rs,imm)           mips32_i_op(p,0x16,rs,0x00,imm)
#define mips32_bltz(p,rs,imm)            mips32_i_op(p,0x01,rs,0x00,imm)
#define mips32_bltzl(p,rs,imm)           mips32_i_op(p,0x01,rs,0x02,imm)
#define mips32_bltzal(p,rs,imm)          mips32_i_op(p,0x01,rs,0x10,imm)
#define mips32_bltzall(p,rs,imm)         mips32_i_op(p,0x01,rs,0x12,imm)
#define mips32_bne(p,rt,rs,imm)          mips32_i_op(p,0x05,rs,rt,imm)
#define mips32_bnel(p,rt,rs,imm)         mips32_i_op(p,0x15,rs,rt,imm)
#define mips32_cache(p,rt,rs,imm)        mips32_i_op(p,0x2f,rs,rt,imm)
#define mips32_lbu(p,rt,rs,imm)          mips32_i_op(p,0x24,rs,rt,imm)
#define mips32_ldc1(p,rt,rs,imm)         mips32_i_op(p,0x35,rs,rt,imm)
#define mips32_ldc1(p,rt,rs,imm)         mips32_i_op(p,0x35,rs,rt,imm)
#define mips32_ldc2(p,rt,rs,imm)         mips32_i_op(p,0x36,rs,rt,imm)
#define mips32_lh(p,rt,rs,imm)           mips32_i_op(p,0x21,rs,rt,imm)
#define mips32_lhu(p,rt,rs,imm)          mips32_i_op(p,0x25,rs,rt,imm)
#define mips32_ll(p,rt,rs,imm)           mips32_i_op(p,0x30,rs,rt,imm)
#define mips32_lui(p,rt,imm)             mips32_i_op(p,0x0f,0x00,rt,imm)
#define mips32_lw(p,rt,rs,imm)           mips32_i_op(p,0x23,rs,rt,imm)
#define mips32_lw(p,rt,rs,imm)           mips32_i_op(p,0x23,rs,rt,imm)
#define mips32_lwl(p,rt,rs,imm)          mips32_i_op(p,0x22,rs,rt,imm)
#define mips32_lwr(p,rt,rs,imm)          mips32_i_op(p,0x26,rs,rt,imm)
#define mips32_ori(p,rt,rs,imm)          mips32_i_op(p,0x0d,rs,rt,imm)
#define mips32_sb(p,rt,rs,imm)           mips32_i_op(p,0x28,rs,rt,imm)
#define mips32_sc(p,rt,rs,imm)           mips32_i_op(p,0x38,rs,rt,imm)
#define mips32_sh(p,rt,rs,imm)           mips32_i_op(p,0x29,rs,rt,imm)
#define mips32_slti(p,rt,rs,imm)         mips32_i_op(p,0x0a,rs,rt,imm)
#define mips32_sltiu(p,rt,rs,imm)        mips32_i_op(p,0x0b,rs,rt,imm)
#define mips32_sw(p,rt,rs,imm)           mips32_i_op(p,0x2b,rs,rt,imm)
#define mips32_swl(p,rt,rs,imm)          mips32_i_op(p,0x2a,rs,rt,imm)
#define mips32_swr(p,rt,rs,imm)          mips32_i_op(p,0x2e,rs,rt,imm)
#define mips32_synci(p,rs,imm)           mips32_i_op(p,0x01,rs,0x1f,imm)
#define mips32_teqi(p,rs,imm)            mips32_i_op(p,0x01,rs,0x0c,imm)
#define mips32_tgei(p,rs,imm)            mips32_i_op(p,0x01,rs,0x08,imm)
#define mips32_tgeiu(p,rs,imm)           mips32_i_op(p,0x01,rs,0x09,imm)
#define mips32_tlti(p,rs,imm)            mips32_i_op(p,0x01,rs,0x0a,imm)
#define mips32_tltiu(p,rs,imm)           mips32_i_op(p,0x01,rs,0x0b,imm)
#define mips32_tnei(p,rs,imm)            mips32_i_op(p,0x01,rs,0x0e,imm)
#define mips32_xori(p,rt,rs,imm)         mips32_i_op(p,0x0e,rs,rt,imm)
#define mips32_bc2f(p,imm)               mips32_i_op(p,0x12,0x08,0x00,imm)
#define mips32_bc2fl(p,imm)              mips32_i_op(p,0x12,0x08,0x02,imm)
#define mips32_bc2tl(p,imm)              mips32_i_op(p,0x12,0x08,0x03,imm)
#define mips32_j(p,imm)                  mips32_j_op(p,0x02,imm)
#define mips32_jal(p, imm)               mips32_j_op(p, 0x03, imm)
#endif
